<template>
  <div>
    <TableBar title="合作方课程">
      <el-button v-if="search.gov_id" @click="goBindCourse" type="primary">选择课程</el-button>
      <el-button v-if="search.course_id" @click="goBindCourse" type="primary">选择合作方</el-button>
    </TableBar>

    <table cellspacing="0" cellpadding="0" class="obj-con-table">
        <thead>
          <tr>
            <td>课程名称</td>
            <td>合作方</td>
            <td>创建时间</td>
            <td>操作</td>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(c, i) in tableData" :key="'course' + i">
            <td>{{c.course_name}}</td>
            <td>{{c.gov_name}}</td>
            <!-- <td>{{c.student_count}}</td> -->
            <td>{{c.create_time}}</td>
            <td>
              <el-button @click="onUnbind(c)" type="primary">解绑</el-button>
            </td>
          </tr>
        </tbody>
    </table>
    <el-pagination
      background
      layout="prev, pager, next, sizes, jumper"
      @current-change="handleCurrentChange"
      @size-change=handleSizeChange
      :current-page.sync="search.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="search.page_size"
      :total="total"
    ></el-pagination>
    <div class="padding-bottom"></div>
  </div>
</template>
<script>
import pageMixin from "@/mixins/pageMixin";
import TableBar from "@/components/TableBar";
import {govModel} from "@/api/models"
export default {
  mixins: [pageMixin],
  components: { TableBar },
  data() {
    return {
      tableData: [],
      total: 0,
      search: {
        gov_id: null,
        course_id: null,
        page: 1,
        page_size: 10
      }
    };
  },
  mounted() {
    let gov_id = this.$route.query.gov_id;
    gov_id && (this.search.gov_id = gov_id)

    let course_id = this.$route.query.course_id;
    course_id && (this.search.course_id = course_id);
    this.getList();
  },
  methods: {
    goBindCourse() {
      this.$router.push(`/gov/course/edit?gov_id=${this.search.gov_id}&course_id=${this.search.course_id}`)
    },
    onUnbind(row) {
      this.$confirm(`确定删除${row.name}`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        }).catch((err) => {
          this.$message({
            type: 'info',
            message: err.message
          });          
        });
    },
    getList() {
      console.log("getList");
      govModel.govCourseList(
        this.search,
        res => {
          this.total = res.total_records;
          this.tableData = res.data
        },
        err => {
          console.log(err);
        }
      );
    }
  }
};
</script>
<style scope lang="scss">

</style>